package com.ss.android.account.b;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import com.bytedance.common.utility.Logger;
import com.ss.android.account.bb;
import com.ss.android.account.Spipe;
import com.ss.android.account.model.SharePlatform;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.util.NetworkUtils;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;

public final class k extends AbsApiThread {
    public static final class k$a {
        public String a;
        public int b;
        public String c;
        public String d;
        public long e;
        public String f;
        public boolean g;
        public final Map h;
        public long i;
        public String j;
        public String k;
        public boolean l;
        public boolean m;
        public String n;
        public String o;
        public long p;

        public k$a() {

            this.h = new HashMap();
        }
    }

    private Handler a;
    private Context b;
    private int c;
    private boolean d;
    private String e;
    private String f;
    private String g;
    private String h;
    private String i;
    private int j;

    public k(Context arg3, Handler arg4, int arg5, String arg6, String arg7, int arg8) {

        this.b = arg3.getApplicationContext();
        this.a = arg4;
        this.c = arg5;
        this.d = true;
        this.e = arg6;
        this.f = null;
        this.g = null;
        this.h = null;
        this.i = arg7;
        this.j = arg8;
    }

    public k(Context arg3, Handler arg4, int arg5, int arg6) {

        this.b = arg3.getApplicationContext();
        this.a = arg4;
        this.c = arg5;
        this.d = false;
        this.e = null;
        this.f = null;
        this.g = null;
        this.h = null;
        this.i = null;
        this.j = arg6;
    }

    public k(Context arg2, Handler arg3, int arg4, String arg5, String arg6, String arg7, String arg8, int arg9) {

        this.b = arg2.getApplicationContext();
        this.a = arg3;
        this.c = arg4;
        this.d = true;
        this.e = arg5;
        this.f = arg6;
        this.g = arg7;
        this.h = arg8;
        this.i = null;
        this.j = arg9;
    }

    public static k$a a(JSONObject arg14) throws Exception {
        k$a v1 = new k$a();
        v1.a = arg14.optString("name");
        v1.b = arg14.optInt("gender");
        v1.c = arg14.optString("screen_name");
        v1.d = arg14.optString("description");
        arg14.optBoolean("is_generated");
        v1.f = arg14.optString("avatar_url");
        v1.e = arg14.optLong("user_id", 0);
        v1.o = arg14.optString("session_key", "");
        v1.g = arg14.optBoolean("user_verified");
        boolean v0 = arg14.optInt("new_user") != 0 ? true : false;
        v1.l = v0;
        v0 = arg14.optInt("is_recommend_allowed") != 0 ? true : false;
        v1.m = v0;
        v1.n = arg14.optString("recommend_hint_message");
        String v0_1 = arg14.optString("mobile");
        SharePlatform.MOBILE.mNickname = v0_1;
        if(!TextUtils.isEmpty(((CharSequence)v0_1))) {
            v1.h.put(SharePlatform.MOBILE.mName, SharePlatform.MOBILE);
        }

        JSONArray v2 = arg14.getJSONArray("connects");
        int v3 = v2.length();
        long v4 = System.currentTimeMillis();
        int v0_2;
        for(v0_2 = 0; v0_2 < v3; ++v0_2) {
            JSONObject v6 = v2.getJSONObject(v0_2);
            String v7 = v6.getString("platform");
            if(v7 != null && v7.length() != 0) {
                SharePlatform v8 = new SharePlatform(v7, 0);
                v8.mNickname = v6.optString("platform_screen_name");
                v8.mAvatar = v6.optString("profile_image_url");
                v8.mPlatformUid = v6.optString("platform_uid");
                long v10 = v6.optLong("expires_in");
                if(v10 > 0) {
                    v8.mExpire = 1000 * v10 + v4;
                }

                v8.mExpireIn = v10;
                v1.h.put(v7, v8);
            }
        }

        JSONObject v0_3 = arg14.optJSONObject("media");
        if(v0_3 != null) {
            v1.j = v0_3.optString("avatar_url");
            v1.i = v0_3.optLong("id");
            v1.k = v0_3.optString("name");
        }

        v1.p = arg14.optLong("media_id");
        return v1;
    }

    public final void run() {
        JSONObject v2_2;
        JSONObject v3;
        String v2_1;
        int v0 = 18;
        Bundle v1 = new Bundle();
        try {
            StringBuilder v2 = new StringBuilder();
            if(this.d) {
                v2.append(Spipe.ssoCallbackV2Url);
                v2.append("?platform=").append(Uri.encode(this.e));
                if(!android.support.design.a.isTextEmpty(this.f)) {
                    v2.append("&access_token=").append(Uri.encode(this.f));
                }

                if(!android.support.design.a.isTextEmpty(this.g)) {
                    v2.append("&expires_in=").append(Uri.encode(this.g));
                }

                if(!android.support.design.a.isTextEmpty(this.h)) {
                    v2.append("&uid=").append(Uri.encode(this.h));
                }

                if(!android.support.design.a.isTextEmpty(this.i)) {
                    v2.append("&code=").append(Uri.encode(this.i));
                }

                if(TextUtils.isEmpty(null)) {
                }else {
                    v2.append("&auth_token=").append(Uri.encode(null));
                }
            }
            else {
                v2.append(Spipe.userInfoUrl);
            }

            v2_1 = NetworkUtils.doGet(4096, v2.toString());
            if(v2_1 == null) {
            }else if(v2_1.length() == 0) {
            }else {
                v3 = new JSONObject(v2_1);
                v2_1 = v3.getString("message");
                if (!"error".equals(v2_1)) {
                    label_114:
                    if (!"success".equals(v2_1)) {
                        Logger.w("snssdk", "user_info status: " + v2_1);
                    } else {

                        k$a v2_3 = k.a(v3.getJSONObject("data"));
                        v0 = 0;
                        if (!this.d) {
                            v0 = this.j;
                        } else if ("1".equals(v3.optString("new_platform"))) {
                            v0 = this.j;
                        }
                        Message v3_1 = this.a.obtainMessage(1001);
                        v3_1.obj = v2_3;
                        v3_1.arg1 = v0;
                        v3_1.arg2 = this.c;
                        this.a.sendMessage(v3_1);
                        return;
                    }
                } else {
                    v2_2 = v3.getJSONObject("data");
                    if (!"session_expired".equals(v2_2.optString("name"))) {
                        if (!this.d) {
                        } else if (!"connect_switch".equals(v2_2.optString("name"))) {
                        } else {
                            v0 = 111;
                            v1.putString("bundle_error_tip", v2_2.optString("description"));
                            v1.putString("extra_confirm_bind_exist_tips", v2_2.optString("dialog_tips"));
                            v1.putString("extra_auth_token", v2_2.optString("auth_token"));
                        }
                    } else {
                        v0 = 105;
                    }
                }
            }
        } catch(Throwable v0_1) {
            v0 = bb.a().a(this.b, v0_1);
        }
        Message v2_4 = this.a.obtainMessage(1002);
        v2_4.arg1 = v0;
        v2_4.arg2 = this.c;
        v2_4.setData(v1);
        this.a.sendMessage(v2_4);
    }
}

